package com.jiang.专题.区间.Q228;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/04/22 14:04
 */
public class Solution {
    public List<String> summaryRanges(int[] nums) {
        List<String> list = new ArrayList<>();
        int start = nums[0];
        int end = nums[0];
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] - nums[i - 1] == 1) {
                end++;
            } else {
                if (start != end) {
                    String s = start + "->" + end;
                    list.add(s);
                } else {
                    list.add(String.valueOf(start));
                }
                start = nums[i];
                end = nums[i];
            }
        }
        if (start != end) {
            String s = start + "->" + end;
            list.add(s);
        } else {
            list.add(String.valueOf(start));
        }
        return list;
    }
}
